<?php

namespace App\Http\Controllers;

use App\Note;
use Illuminate\Http\Request;

class NoteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('pages.note',[
            'note' => Note::with(['user:id,nickname','zone'])->paginate(10)
        ]);
    }


    public function destroy(Note $note)
    {
        $imglist = collect(json_decode($note->image_src));
        foreach ($imglist->pop() as $value) {
            $oldFile = Str::after($value, "http://craftsman.test/storage/");
            Storage::delete(Str::finish("public/", $oldFile));
        };
        $note->delete();
        return back()->withStatus(__('手记移除成功'));
    }
}
